<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function mytostring(foo){
            // var foo= 'get-element-by-id'
            //根据某个字符进行切割
            var arr = foo.split('-');
            console.log(arr)
            //获取每个元素中的第一个字符并转换成大写 并与后面字母的进行连接
            // console.log(arr[1].charAt(0).toUpperCase() + arr[1].substr(1, arr[1]. length -1));
            for (var i = 1;i< arr.length; i++) {

                arr[i]=arr[i].charAt(0).toUpperCase()+arr[i].substr(1,arr[i].length-1)
            }
            //根据某个字符将数组转成字符串
            console. log(arr.join(''));
        }
        
        mytostring('get-element-by-id');
    </script>
</body>
</html>